/**
 * Created by Kevin.
 */


window.onload = function getDataset() {
	//数据集总浏览数  
    $.ajax({
    	url:  DataOpen.apiHostName + '/dataopen/statistics/general/totalView',
        method: 'GET',
        dataType: 'json',
        async:true, //异步执行
    }).done(function(data, res, status) {
        if (data.code == "success") {
            $("#totalDatasetView").text(data.data.count); 
        }
    });
    
  //数据集总调用数  
    $.ajax({
    	url:  DataOpen.apiHostName + '/dataopen/statistics/general/totalDatasetCall',
        method: 'GET',
        dataType: 'json',
        async: true, //异步执行
    }).done(function(data, res, status) {
        if (data.code == "success") {
            $("#totalDatasetCall").text(data.data.count);
        }
    });
    
  //开放数据集数量  
    $.ajax({
    	url:  DataOpen.apiHostName + '/dataopen/statistics/general/totalDataset',
        method: 'GET',
        dataType: 'json',
        async: true, //异步执行
    }).done(function(data, res, status) {
        if (data.code == "success") {
            $("#totalDataset").text(data.data.count);
        }
    });
    
  //用户总数 
    $.ajax({
    	url:  DataOpen.apiHostName + '/dataopen/statistics/general/totalUsers',
        method: 'GET',
        dataType: 'json',
        async: true, //异步执行
    }).done(function(data, res, status) {
        if (data.code == "success") {
            $("#totalUsers").text(data.data.count);
        }
    });
    
   //开放文件数量
    $.ajax({
    	url:  DataOpen.apiHostName + '/dataopen/statistics/data/totalFile',
        method: 'GET',
        dataType: 'json',
        async:true, //异步执行
    }).done(function(data, res, status) {
        if (data.code == "success") {
            $("#totalFile").text(data.data.count);
        }
    });
    
    
   //开放数据部门数
    $.ajax({
    	url:  DataOpen.apiHostName + '/dataopen/statistics/general/totalOrg',
        method: 'GET',
        dataType: 'json',
        async:true, //异步执行
    }).done(function(data, res, status) {
        if (data.code == "success") {
            $("#totalOrg").text(data.data.count);
        }
    });
	 
  //数据集下载Top10
   $.each(function (i, o) {
            if (typeof(dataState[i] != "undefined")) dataState[i] = decodeURI(o);
        });
        $.ajax({
            url: DataOpen.apiHostName + '/dataopen/statistics/dataset/topByType?order=1&dataType=0&topNum=10',
            method: 'GET',
            dataType: 'json',
            async:true, //异步执行
            data: {topNum:10}
        }).done(function(data, res, status) {
            if (data.code == "success") {

                // Get and Parse the template
                var tpl = $.trim(document.getElementById("DataCallsTop10").innerHTML);
                Mustache.parse(tpl);

                // Get root node of this list from page
                var root = $(".Top10Box01").empty();
                var itemObject;
                var DataNumber = 0;
                $.each(data.data, function(index, item) {
                	DataNumber++;
                	if (DataNumber <= 4) {
                    	$(".DataList_Download02").addClass("DataList_Download01").removeClass("DataList_Download02")
                    }else{
                    	$(".DataList_Download02").addClass("DataList_Download02").removeClass("DataList_Download01")
                    	};
                    	
                    itemObject = {
                    	DataNumber:DataNumber,
                        DataCallsTop10Name:item.name,
                        DataCallsTop10Count: item.count,
                       };

                    $(root).append(Mustache.render(tpl, itemObject));
                      
                });
                
            }
        });
    
    
      //应用调用量Top10
        $.each(function (i, o) {
                 if (typeof(dataState[i] != "undefined")) dataState[i] = decodeURI(o);
             });
             $.ajax({
                 url: DataOpen.apiHostName + '/dataopen/statistics/dataset/topByType?order=1&dataType=3&topNum=10',
                 method: 'GET',
                 dataType: 'json',
                 async:true, //异步执行
                 data: {topNum:10}
             }).done(function(data, res, status) {
                 if (data.code == "success") {

                     // Get and Parse the template
                     var tpl = $.trim(document.getElementById("AppCallsTop10").innerHTML);
                     Mustache.parse(tpl);

                     // Get root node of this list from page
                     var root = $(".Top10Box02").empty();
                     var itemObject;
                     var DataNumber = 0;
                     $.each(data.data, function(index, item) {
                         //DataOpen.printConsole(el);
                     	DataNumber++;
                     	if (DataNumber <= 4) {
                         	$(".AppList_Download02").addClass("AppList_Download01").removeClass("AppList_Download02")
                         }else{
                         	$(".AppList_Download02").addClass("AppList_Download02").removeClass("AppList_Download01")
                         	};
                         	
                         itemObject = {
                         	DataNumber:DataNumber,
                             DataCallsTop10Name:item.name,
                             DataCallsTop10Count: item.count,
                            };

                         $(root).append(Mustache.render(tpl, itemObject));
                           
                     });
                     
                 }
             });
}
 
 //文件数据总数
 var FilesCount = function(){
	    var FilesCount;
	    $.ajax({
	    	 method: 'GET',
	         async : false, //同步执行
	         url : DataOpen.apiHostName + '/dataopen/statistics/data/totalFile',
	         dataType : "json", //返回数据形式为json
	         success : function(data, res, status) {
	        	 if (data.code == 'success') {
	        		FilesCount = data.data.count;
	        	 }      
	        },
	   })
	   return FilesCount;
	 }; 
 
//API数据总数
var APICount = function(){
	    var APICount;
	    $.ajax({
	    	 method: 'GET',
	         async : false, //同步执行
	         url : DataOpen.apiHostName + '/dataopen/statistics/data/totalAPI',
	         dataType : "json", //返回数据形式为json
	         success : function(data, res, status) {
	        	 if (data.code == 'success') {
	        		 APICount = data.data.count;
	        	 }      
	        },
	   })
	   return APICount;
	 };

//应用数据总数
var LinkCount = function(){
	    var LinkCount;
	    $.ajax({
	    	 method: 'GET',
	         async : false, //同步执行
	         url : DataOpen.apiHostName + '/dataopen/statistics/data/totalLink',
	         dataType : "json", //返回数据形式为json
	         success : function(data, res, status) {
	        	 if (data.code == 'success') {
	        		 LinkCount = data.data.count;
	        	 }      
	        },
	   })
	   return LinkCount;
	 }; 